package com.xmy.cultivate.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xmy.cultivate.entity.TrainAuditTeacherDetail;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 审核老师设置对应的详情 Mapper 接口
 * </p>
 *
 * @author hpiggy
 * @since 2025-07-01
 */
@Mapper
public interface TrainAuditTeacherDetailMapper extends BaseMapper<TrainAuditTeacherDetail> {


    @Select({ "<script>",
            "SELECT t1.*, getSchoolName(t1.school_id) AS schoolName, t2.name AS teacherName,t3.name as stations_name",
            "FROM train_audit_teacher_detail AS t1",
            "LEFT JOIN staff AS t2 ON t1.teacher_id = t2.id",
            "LEFT JOIN skill_stations AS t3 ON t1.stations_id = t3.id",
            "WHERE 1=1",
            "<if test='schoolId != null and schoolId != &apos;&apos;'>",
            "AND t1.school_id = ${schoolId}",
            "</if>",
//            "<if test='auditTeacherSetId != null auditTeacherSetId != &apos;&apos;'>",
//            "AND t1.audit_teacher_set_id = ${auditTeacherSetId}",
//            "</if>",
//            "<if test='auditTeacherSetId != null and auditTeacherSetId != &apos;&apos;'>",
            "AND t1.audit_teacher_set_id = ${auditTeacherSetId}",
//            "</if>",

            "<if test='teacherName != null and teacherName != &apos;&apos;'>",
            "AND t2.name LIKE '%${teacherName}%'",
            "</if>",

            "<when test='versionIdList != null and versionIdList!=&apos;&apos; and versionIdList.size() > 0'> ",
            "<foreach collection='versionIdList' item='item' open='AND(' separator='or' close=')'>",
                "FIND_IN_SET(${item},version_id_str)",
            "</foreach>",
            ")",
            "</when>",
            "ORDER BY t1.created_at DESC",
            "</script>"})
    public IPage<TrainAuditTeacherDetail> findAll(
        IPage<TrainAuditTeacherDetail> page,
        @Param("schoolId") String schoolId,
        @Param("auditTeacherSetId") String auditTeacherSetId,
        @Param("teacherName") String teacherName,
        @Param("versionIdList") List<String> versionIdList
    );


}
